package mapred.config;

import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.lib.IdentityReducer;

@SuppressWarnings("unchecked")
public class ReduceConfig {

    private Class<? extends Reducer> reducerClass;

    private int numReduceTasks;

    private ReduceConfig(Class<? extends Reducer> reducerClass,
            int numReduceTasks) {
        if (reducerClass == null) {
            this.reducerClass = IdentityReducer.class;
        } else {
            this.reducerClass = reducerClass;
        }
        this.numReduceTasks = numReduceTasks;
    }

    public static ReduceConfig newInstance(
            Class<? extends Reducer> reducerClass, int numReduceTasks) {
        return new ReduceConfig(reducerClass, numReduceTasks);
    }

    public Class<? extends Reducer> getReducerClass() {
        return reducerClass;
    }

    public int getNumReduceTasks() {
        return numReduceTasks;
    }

    public void replace(AppConfig app) {
        if (app.contains("-reduce")) {
            numReduceTasks = Integer.parseInt(app.get("-reduce"));
        }
    }

}
